package model;

/**
 * Class extending field containing common methods for fields that can be owned.
 * @author Mike
 *
 */
public abstract class Ownable extends Field  
{
	protected int price;
	protected Player owner = null;
	protected int payment;
	protected boolean pawned;
	
	/**
	 * Constructor adds values for Number, Name, Description and price.
	 * @param number: Field number
	 * @param name: Field name
	 * @param description: Field description
	 * @param price: Field price
	 */
	public Ownable(int number, String name, String description, int price) 
	{
		super(number, name, description);
		this.price = price;
	}
	
	public abstract int rent();
	public abstract int valueOfAssets();
	public abstract int numOfHouses();
	public abstract int numOfHotels();
	public abstract boolean isPawned();
	
	/**
	 * Sets the fields owner as the buying player and withdraws the price from his account.
	 * @param player: object of type Player
	 */
	public void buy(Player player) 
	{
		owner = player;
		player.withdraw(price);
	}
	
	/**
	 * sets the variable pawned to true, for use when a field is being pawned.
	 */
	public void pawn()
	{
		pawned = true;
	}
	
	/**
	 * sets the variable pawned to false, for use when a field is being unpawned.
	 */
	public void unpawn()
	{
		pawned = false;
	}
	
	/**
	 * Returns whether the field has an owner.
	 * @return boolean value
	 */
	public boolean isOwned()
	{
		return (owner != null);
	}
	
	/**
	 * Getter, returns owner.
	 * @return owner: object of type Player
	 */
	public Player getOwner()
	{
		return owner;
	}
	
	/**
	 * Clears the field for when its owner is out of the game.
	 */
	public void clear()
	{
		this.owner = null;
		pawned = false;
	}
	
	/**
	 * setter, sets the owner.
	 * @param owner: object of type Player
	 */
	public void setOwner(Player owner)
	{
		this.owner = owner;
	}
	
	/**
	 * Getter, returns the actual number of the player owning the field.
	 * @return owners number or -1
	 */
	public int getOwnerNumber()
	{
		if (owner != null)
		return owner.getNumber();
		
		else 
			return -1;
	}

	/**
	 * Getter, returns the price.
	 * @return price: value for field price
	 */
	public int getPrice() {
		return price;
	}

	/**
	 * To string method.
	 */
	@Override
	public String toString() {
		return super.toString() + "Ownable [price=" + price + ", owner=" + owner + "]. ";
	}
	
	/**
	 * Getter, returns negative payment.
	 */
	@Override
	public int getPayment(){
		return -payment;
	}
}
